import { Input, Output, EventEmitter } from '@angular/core';

import { ComponentBase } from './share';

export abstract class ReinitializableComponentBase extends ComponentBase {
    @Input() protected toBeReinitialize = false;
    @Output() protected toBeReinitializeChange = new EventEmitter<boolean>();

    prepareToReinitialize(): any {
        if (this.toBeReinitialize) {
            let result = this.initialize();
            this.toBeReinitialize = false;
            setTimeout(() => this.toBeReinitializeChange.next(false), 0);

            return result;
        }

        return null;
    }

    protected abstract initialize(): any;
}